package com.xjj.servicejob.consumer;

import com.rabbitmq.client.Channel;
import com.xjj.entity.JobSubmit;
import com.xjj.entity.Student;
import com.xjj.servicejob.service.JobSubmitService;
import com.xjj.servicejob.vo.InitJobSubmitVo;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author sjy
 * @create 2022-10-24 10:58
 */
@Component
public class MyConsumer {
    @Autowired
    private JobSubmitService jobSubmitService;
    /**
     * 监听initJobSubmit消息队列
     * @param initJobSubmitVo
     * @param message
     * @param channel
     */
    @RabbitListener(queues = "initJobSubmit")
    public void receiveEmail(InitJobSubmitVo initJobSubmitVo, Message message, Channel channel){
        Integer jobId = initJobSubmitVo.getJobId();
        List<Student> students = initJobSubmitVo.getStudent();
//        jobSubmitService
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            JobSubmit jobSubmit = new JobSubmit();
            jobSubmit.setStudentId(student.getId());
            jobSubmit.setJobId(jobId);
            jobSubmit.setStatus("c");
            jobSubmitService.save(jobSubmit);
        }
        System.out.println("students:"+students);
        System.out.println("message:"+message);
        System.out.println("处理初始化提交作业");
        System.out.println("--------");
    }
}
